#include "thingsbehind.h"
#include "ui_thingsbehind.h"
#include "menu.h"
#include <QPainter>
#include <QFont>
#include <QPixmap>
#include <QTimer>

int i0=1;//第一次循环
int iend=18;//第二次循环

thingsbehind::thingsbehind(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::thingsbehind)
{
    ui->setupUi(this);
    this->setAttribute(Qt::WA_DeleteOnClose);
}

void thingsbehind::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    painter.setPen(Qt::black);//设置画笔颜色
    painter.setBrush(Qt::black);//设置填充颜色
    painter.drawRect(0,0,480,480);
    int x1=ui->qhframe->pos().x();
    int y1=ui->qhframe->pos().y();
    qh[0].load(":/resourse/1.png") ;
    qh[1].load(":/resourse/p6.png") ;
    qh[2].load(":/resourse/p7.JPG") ;
    qh[3].load(":/resourse/p8.JPG") ;
    qh[4].load(":/resourse/p9.png") ;
    qh[5].load(":/resourse/p10.JPG") ;
    qh[6].load(":/resourse/p11.png") ;
    qh[7].load(":/resourse/p12.JPG") ;
    QFont font1("Courier New",15);
    painter.setFont(font1);
    painter.setPen(Qt::white);
    painter.setBrush(Qt::white);
    if (playthrough>=4)//第二次循环
    {
        if (i0<=13)
        {
            painter.drawText(20,370,dialog[iend]);
        }
        else
        {
            painter.setPen(Qt::red);
            painter.setBrush(Qt::red);
            painter.drawText(20,370,dialog[iend]);
        }
    }
    else//第一次循环
    {
        if (i0<=13&&playthrough<=3)
        {
            if (playthrough==1)
            {
                painter.drawText(20,370,dialog[i0]);
            }
            else
            {
                if (i0!=4)
                {
                    painter.drawText(20,370,dialog[i0]);
                }
                else
                {
                    i0=16;
                    painter.drawText(20,370,dialog[i0]);
                    i0=5;
                }
            }
        }
        if (i0==14)
        {
            painter.setPen(Qt::red);
            painter.setBrush(Qt::red);
            painter.drawText(20,370,dialog[i0]);
        }
    }
    if (i0==4||i0==5||i0==6||i0==7)
    {
        painter.drawPixmap(x1,y1,ui->qhframe->width(),ui->qhframe->height(),qh[0]);
    }
    if (i0==8)
    {
        painter.drawPixmap(x1,y1,ui->qhframe->width(),ui->qhframe->height(),qh[6]);
    }
    if (i0==9)
    {
        painter.drawPixmap(x1,y1,ui->qhframe->width(),ui->qhframe->height(),qh[1]);
    }    
    if (i0==10)
    {
        painter.drawPixmap(x1,y1,ui->qhframe->width(),ui->qhframe->height(),qh[4]);
    }
    if (i0==11)
    {
        painter.drawPixmap(x1,y1,ui->qhframe->width(),ui->qhframe->height(),qh[5]);
    }
    if (i0==12)
    {
        painter.drawPixmap(x1,y1,ui->qhframe->width(),ui->qhframe->height(),qh[2]);
    }
    if (i0==13)
    {
        painter.drawPixmap(x1,y1,ui->qhframe->width(),ui->qhframe->height(),qh[3]);
    }
    if (i0==14)
    {
        painter.drawPixmap(x1,y1,ui->qhframe->width(),ui->qhframe->height(),qh[7]);
    }
    if (i0==15)
    {
        i0=1;
        iend=18;
        if (playthrough==1||playthrough==2)
        {
            playthrough++;
        }
        this->close();
        Menu *M =new Menu();
        M->show();
    }

}

void thingsbehind::on_nextpushButton_clicked()
{
    i0++;
    if (playthrough>=4)
    {
        iend++;
    }
    update();
}

thingsbehind::~thingsbehind()
{
    delete ui;
}
